package fun.linze.wallpaperwebsite.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<JwtAuthenticationFilter> jwtFilter() {
        FilterRegistrationBean<JwtAuthenticationFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new JwtAuthenticationFilter());
        // 拦截所有 /api/v1/**
        registrationBean.addUrlPatterns("/api/v1/*");
        // 放行注册、登录、标签相关接口（正则匹配）
        registrationBean.addInitParameter("excludeUrls",
                "/api/v1/register,/api/v1/login,/api/v1/tag,/api/v1/tags");
        registrationBean.setOrder(1);
        return registrationBean;
    }
}

